﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
using System.Reflection;
using System.Web.Security;

namespace WEBEasyUIDemo.ashx
{
    /// <summary>
    /// LoginHandler 的摘要说明
    /// </summary>
    public class LoginHandler : IHttpHandler
    {
        HttpRequest Request;
        HttpResponse Response;
        HttpSessionState Session;
        HttpServerUtility Server;
        HttpCookie Cookie;
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            Request = context.Request;
            Response = context.Response;
            Session = context.Session;
            Server = context.Server;
            string login = context.Request.Params["action"];
            switch (login)
            {
                case "Login":  //获取特定用户能看到的菜单（左侧树）
                    MethodInfo methodInfo = this.GetType().GetMethod(login);//反射调用方法
                    methodInfo.Invoke(this, null);// 使用指定的参数调用当前实例所表示的方法或构造函数。
                    break;
                case "logout":
                    FormsAuthentication.SignOut();
                    context.Response.Write("{\"msg\":\"退出成功！\",\"success\":true}");
                    break;
                default:
                    context.Response.Write("{\"msg\":\"参数错误！\",\"success\":false}");
                    break;
            }
        }
        /// <summary>
        /// 登陆
        /// </summary>
        public void Login()
        {
            Response.Write("0"); 
            //bool b = false;
            //string username = Request["username"].ToString();
            //string password = Request["password"].ToString();
            //if (username == "admin" && password == "admin")
            //    b = true;
            //if (username == string.Empty && password == string.Empty)
            //    b = true;
            ////Cookie
            //Cookie = new HttpCookie("RoleInfo");
            //Cookie["username"] = username;
            //Cookie.Expires = DateTime.Now.AddMonths(1);
            //Response.Cookies.Add(Cookie);
            //if (b)
            //    Response.Write("0");
            //else
            //    Response.Write("1");

        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}